package com.ciner.main;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RatingBar;


import com.ciner.R;
import com.ciner.database.CinerDbAdapter;

public class NewMovieActivity extends Activity implements OnClickListener {

	private EditText title, description, duration, year, genre, starring;
	private RatingBar rating;
	private Button button;
	private ImageButton image;

	private CinerDbAdapter dbAdapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		dbAdapter = new CinerDbAdapter(this);

		setContentView(R.layout.new_movie);

		title = (EditText) findViewById(R.id.title_text);
		description = (EditText) findViewById(R.id.description);
		duration = (EditText) findViewById(R.id.duration_text);
		year = (EditText) findViewById(R.id.year_text);
		genre = (EditText) findViewById(R.id.genre_text);
		starring = (EditText) findViewById(R.id.starring_text);
		rating = (RatingBar) findViewById(R.id.set_rating);
		button = (Button) findViewById(R.id.done_button);
		image = (ImageButton) findViewById(R.id.cover_button);

		button.setOnClickListener(this);
	}

	public void onPause() {
		super.onPause();
		dbAdapter.close();
	}

	public void onResume() {
		super.onResume();
		dbAdapter.open();
	}

	public void onClick(View v) {
		if (v.getId() == R.id.done_button) {
			dbAdapter.createMovie(title.getText().toString(), description.getText().toString(),
					Integer.parseInt(duration.getText().toString()), 
					Integer.parseInt(year.getText().toString()),
					(int)rating.getRating(), image.toString());
		}
	}

}
